<?php


namespace App\Http\Controllers\Admin;
use \App\Http\Controllers\BaseController;
use App\Response\Response;
use Illuminate\Http\Request;

class IndexNavController extends BaseController
{
    /**
     * @api {get} /index/nav/list 金刚区列表
     * @apiVersion 0.1.1
     * @apiName 金刚区列表
     * @apiGroup 金刚区管理
     * @apiParam {number} page
     * @apiParam {number} perPage
     * @apiSuccessExample 成功响应
    {
    "code": 200,
    "data": {
        "current_page": 1,
        "data": [
                {
                "id": 2,
                "name": "福利中心",
                "sort": 8,
                "icon": "https://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/ios_images/2019-11-10/37ECDBAC-0C22-40D0-8557-369AF16132BA.jpg",
                "version": 0,
                "link_url": "",
                "client_type": 1,
                "type": 1
                }
     ]
    },
    "meta": {
    "page（页数）": 1,
    "limit（每页数量）": 10,
    "next（下一页）": "http://admin.rh/gift/list?=2",
    "total（总数）": 37
    }
    }
    }
     *
     */

    public function getIndexNavListApi(Request $request)
    {
        $page = $request->input('page', 1);
        $perPage = $request->input('perPage', 20);
        $indexNavList = app('repo_index_nav')->getIndexNavList($page, $perPage);
        return Response::sendData($indexNavList);
    }

    /**
     * @api {post} /index/nav/update 更新金刚区
     * @apiVersion 0.1.1
     * @apiName 金刚区动态
     * @apiGroup 金刚区管理
     *
     * @apiParam {number} op_type  0删除 1添加更新
     * @apiParam {number} id 删除传具体ID 更新传具体ID 新增传0
     * @apiParam {string} name 名称 以上字段 删除不用传
     * @apiParam {number} sort 排序号
     * @apiParam {string} icon icon地址
     * @apiParam {number} version 版本
     * @apiParam {string} link_url 跳转地址
     * @apiParam {number} client_type 客户端渠道1全部2安卓3IOS
     * @apiParam {number} type 跳转方式1URI方式2H5方式
     * @apiSuccessExample 成功响应
     * {"code":200,"data":true}
     * @apiError 98031  更新金刚区失败
     * @apiErrorExample 错误响应
     *
     *      {
     *          "code": 98031,
     *          "message": "errorMsg"
     *      }
     *
     */

    public function upIndexNavApi(Request $request)
    {
        $opType = $request->input('op_type', 1);
        if ($opType == 1){ //添加
            $indexNav = $request->only(['id', 'sort', 'name', 'icon', 'version','link_url','client_type','type']);
            app('repo_index_nav')->upIndexNav($indexNav);

        }else{
            $id = $request->input('id', 1);
            app('repo_index_nav')->del($id);
        }
        return Response::sendData(true);

    }

}
